extend personLeft_s.pug

block append pageStyle
	link(href='${relativePath}/static/css/personCenter/personIndex.css' type="text/css" rel="stylesheet")
	link(href='${relativePath}/static/css/personCenter/suppliers.css' type="text/css" rel="stylesheet")
	link(href="${relativePath}/static/css/shopping/foundation.min.css" rel="stylesheet" type="text/css")
	link(href="${relativePath}/static/css/shopping/foundation-datepicker.css" rel="stylesheet" type="text/css")

block personRight
	div.rightContent.fl
		div.timeHead
			div.allTime
				span.havaM.timeTitle.fl 时间：
				div.selectTime.fl
					input#startTime.fl(type="text" time="starTime" placeholder="请选择")
					i.fl.line -
					input#endTime.fl(type="text" time="endTime" placeholder="请选择")
				div.latestTime.havaM.fl#dateType
					span.latest 最近：
					span.current(dateType="1") 一个月
					span(dateType="2") 三个月
					span(dateType="3") 一年
		div.goodsContent
			div.goodsTitle
				ul
					li.goodName 商品名称
					li.goodsMsg 商品信息
					li.unit 单价
					li.goodNum 数量
					li.allCount 总价
					li.tradStatus 交易状态
					li.tradOpera 交易操作
			div.allLists
				//- 列表内容
				
			div.clear
			//- 拒单弹层
			div.refuseMask
				div.refuseBox
					div.top 拒单原因
					div.refuseCon
						div.row.rowOne
							label.refuseR.fl 建议报价：
							input.txt.day
							i 元
						div.row.rowOne
							label.refuseR.fl 建议工期：
							input.txt.date
							i 天
						div.row
							label.refuseR.fl 拒绝原因：
							textarea.fl.reason(maxlength="150")
						p
							a.btn.btnSure(href="javascript:;") 确定
							a.btn.btnCancle(href="javascript:;") 取消

	//- 订单列表模板
	script#orderLists(type="text/html")
		| {{set data = data.data}}
		| {{each data arr}}
		div.listOne(orderid="{{arr.order_id}}" type="{{arr.order_type}}" skuid="{{arr.sku_id}}")
			| <div class="listTop {{if arr.order_state == 0 || arr.order_state == 120}} gray {{/if}}">
			|	<span class="time"> {{arr.create_time}}</span>
			|	<span class="order"> 订单号：{{arr.order_sn}}</span>
			|	<span> {{arr.company_name}}</span>
			| {{if arr.expiry_time != 0}}
			| <div class="countdown fr" data-endtime="<%=getExpiryTime(arr.expiry_time)%>" style="display:inline-block;">
			//- | 	<span class="secondTime fr"> {{arr.expiry_time}}</span>
			| 		<span class="secondTime fl" ct-h>00</span><i class="fl">:</i><span class="secondTime secondTime01 fl" ct-mi>00</span><i class="fl">:</i><span class="secondTime secondTime02 fl" ct-s>00</span>
			| </div>
			| {{/if}}
			| {{if arr.order_state == 0 || arr.order_state == 120}}
			| <span class="delete delete1 fr"></span>
			| {{/if}}
			| </div>
			div.listContent
				div.commentsBox
					div.listLeft.fl
						div.imgBox.fl
							img(src="{{arr.img}}")
						div.imgTxt.fl
							<h3> {{arr.goods_name}}</h3>
							p 备注：{{arr.member_explain}}
					div.msgBoxList.fl
						| {{set list = arr.sku_list}}
						| {{each list temp}}
						p {{temp.spec_name}}：{{temp.opt_name}}
						| {{/each}}
					div.unitBoxList.fl
						p.unit {{arr.goods_price}}
					div.numberBoxList.fl {{arr.goods_num}}
					div.allCounts.fl {{arr.amount_price}}
					div.tradStatusList.fl
						| {{if arr.order_state == 0}}
						p 系统取消
						| {{else if arr.order_state == 10}}
						p 客户取消
						| {{else if arr.order_state == 20}}
						p 等待确认
						| {{else if arr.order_state == 30}}
						p 等待买家付款
						| {{else if arr.order_state == 40}}
						p 已付款, 未付完
						| {{else if arr.order_state == 50}}
						p 等待发货
						| {{else if arr.order_state == 60}}
						p 已发货
						| {{else if arr.order_state == 70}}
						p 已收货
						| {{else if arr.order_state == 80}}
						p 买家申请退款
						| {{else if arr.order_state == 81}}
						p 退款退货申请
						| {{else if arr.order_state == 82}}
						p 退货申请
						| {{else if arr.order_state == 83}}
						p 维修申请
						| {{else if arr.order_state == 84}}
						p 售后结束
						| {{else if arr.order_state == 90}}
						p 同意售后
						| {{else if arr.order_state == 91}}
						p 拒绝售后
						| {{else if arr.order_state == 100}}
						p 已拒绝该订单
						| {{else if arr.order_state == 110}}
						p 已结算
						| {{/if}}
						p
							a.orderLinkDatail(href="javascript:;") 订单详情
					div.tradOperation.fl
						//- | {{if arr.order_state > 60}}
						//- p
						//- 	a.reSubmit.rightNow.goPj(href="javascript:") 评  价
						//- | {{/if}}
						| {{if arr.contents != null}}
						p
							a.lookPj(href="javascript:;") 查看评价 >

						| {{/if}}
						| {{if arr.order_state == 50}}
						p
							a.rightNow.delivery(href="javascript:") 发货
						| {{/if}}
						| {{if arr.order_state == 20}}
						p
							a.sureSh.rightNow(href="javascript:") 确认
						p
							a.refused(href="javascript:") 拒绝
						| {{/if}}
						| {{if arr.order_state == 60}}
						p
							a(href="javascript:;").cancleOrderBtn2 等待买家收货
						| {{/if}}
						| {{if arr.order_state == 70}}
						p
							a(href="javascript:;").cancleOrderBtn3 已收货
						| {{/if}}
						| {{if arr.order_state == 80 || arr.order_state == 81 || arr.order_state == 82 || arr.order_state == 83}}
						p
							a.agreeSh.rightNow(href="javascript:") 同意售后
						p
							a.refusedSale(href="javascript:") 拒绝售后
						| {{/if}}
				div.clear
			| {{if arr.order_type == 1 }}
			//- 图片列表
			div.designBox
				| {{set imgs = arr.order_img}}
				| {{if imgs.length != 0}}
				div.line
				div.designImg
					span.pic.fl 效果图：
					ul.fl
						| {{each imgs img}}
						li.fl
							img(src="{{img}}")
						| {{/each}}
				| {{/if}}
				| {{set txt = arr.order_files}}
				| {{if txt.length != 0}}
				div.designImg.closeure
					span.pic.txt.fl &nbsp;&nbsp;&nbsp;&nbsp;附件：
					| {{each txt fjHerf}}
					div.txtBox.fl
						p.list
							a(href="{{fjHerf}}" target="_blank") 标识汇-智能商城
							span.delete.fr
					| {{/each}}
				| {{/if}}
			| {{/if}}

			//- 查看评价内容
			| {{if arr.contents != null}}
			div.lookComment
				p.star
					| {{if arr.point == 1}}
					i.iconStar.current
					i.iconStar
					i.iconStar
					i.iconStar
					i.iconStar
					| {{else if arr.point == 2}}
					i.iconStar.current
					i.iconStar.current
					i.iconStar
					i.iconStar
					i.iconStar
					| {{else if arr.point == 3}}
					i.iconStar.current
					i.iconStar.current
					i.iconStar.current
					i.iconStar
					i.iconStar
					| {{else if arr.point == 4}}
					i.iconStar.current
					i.iconStar.current
					i.iconStar.current
					i.iconStar.current
					i.iconStar
					| {{else if arr.point == 5}}
					i.iconStar.current
					i.iconStar.current
					i.iconStar.current
					i.iconStar.current
					i.iconStar.current
					| {{/if}}
					//- | <span>满意</span>
				p.commentTxt {{arr.contents}}
				ul.imgBox
					| {{set lists = arr.contentImgs}}
					| {{each lists imgList}}
					li
						img(src="{{imgList}}")
					| {{/each}}
			| {{/if}}
			div.clear
		| {{/each}}

	//- 分页
	div.pageBox
		nav.pageNav
			div.paginationOne.page




block append pageScript
	script(type="text/javascript" src="${relativePath}/static/js/moment.js")
	script(type="text/javascript" src="${relativePath}/static/js/countdown.js")

	script.
		template.defaults.imports.getExpiryTime = function getExpiryTime(timeStr) {
			//- 模板自定义函数，计算倒计时过期时间
			if(timeStr) {
				var ms = new Date().getTime();
				var timeArray = timeStr.split(":");
				return ms + parseInt(timeArray[0]) * 24 * 60 * 1000
					+ parseInt(timeArray[1]) * 60 * 1000
					+ parseInt(timeArray[0]) * 1000;
			}
			return 0;
		}
		$(function(){
			moment().format('MMMM Do YYYY, h:mm:ss a');
			var nowTemp = new Date();
			var now = new Date(nowTemp.getFullYear(), nowTemp.getMonth(), nowTemp.getDate(), 0, 0, 0, 0);
			var checkin = $('#startTime').fdatepicker({
				format: 'yyyy-mm-dd',
				//- onRender: function (date) {
				//- 	return date.valueOf() < now.valueOf() ? 'disabled' : '';
				//- }
			}).on('changeDate', function (ev) {
				if (ev.date.valueOf() > checkout.date.valueOf()) {
					var newDate = new Date(ev.date)
					newDate.setDate(newDate.getDate() + 1);
					checkout.update(newDate);
				}
				checkin.hide();
				$('#endTime')[0].focus();
			}).data('datepicker');
			var checkout = $('#endTime').fdatepicker({
				format: 'yyyy-mm-dd',
				onRender: function (date) {
					return date.valueOf() < checkin.date.valueOf() ? 'disabled' : '';
				}
			}).on('changeDate', function (ev) {
				checkout.hide();
			}).data('datepicker');

			//- 当前选中
			$(".navList li:nth-child(2)").addClass("current").siblings().removeClass("current");
			$(".roles .supplier").addClass("current").siblings().removeClass("current");
			$(".dfk").addClass("current").siblings("a").removeClass("current");
			//- 全部订单
			//- 点击全部订单、
			function allOrder(pageNum,dateType,start_time,finish_time,order_state){
				$.getJSON(shopIp+"/Order/orderList?callback=?",{
					os:"web",
					userToken:token,
					type:"seller",
					size:5,
					page:pageNum,
					dateType:dateType,
					start_time:start_time,
					finish_time:finish_time,
					order_state:order_state
				},function(data){
					var dataTwo = data.data;
					var tempList = template("orderLists",data);
					if(dataTwo.data == null ) {
						$(".allLists").html("<img class='imgBig' src='${relativePath}/static/imgs/zw.png'/>");
						$(".allLists").css("text-align","center");
					} else{
						$(".allLists").html(tempList);
						$(".allLists .countdown").countdown();
					}
					$(".page").html("").pagination({
						pageCount : data.data.pageCount,
						current : pageNum,
						keepShowPN : true,
						count : 2,
						homePage : "1",
						endPage : data.data.pageCount,
						coping : true,
						prevContent : "< 上一页",
						nextContent : "下一页 >",
						callback : function(page) {
							allOrder(page.getCurrent());
						}
					});
				})
			}
			allOrder(1,"","","",30);

			//- 点击一个月、一年时间筛选
			$("#dateType span[dateType]").click(function() {
				$(".allLists").html("");
				$(this).addClass("current").siblings().removeClass("current");
				allOrder(1,$(this).attr("dateType"),"","",30);
			})

			$(".selectTime input[time='endTime']").change(function() {
				allOrder(1,"",$("#startTime").val(),$(this).val(),30)
			})

			//- 点击待付款
			$(".dfk").click(function() {
				allOrder("","","","",30);
			})
			//- 点击取消订单
			$(".allLists").on("click",".cancleOrderBtn",function() {
				var $this = $(this);
				layer.confirm('您确定取消此订单？', {
					btn: ['确定','取消'],//按钮
					title:"取消此订单"
				}, function(){
					$.post(shopIp+"/OrderBuyer/cancelOrder",{
						userToken:token,
						order_id:$this.closest(".listOne").attr("orderid"),
					},function(data) {
						//console.log(data.msg);
						if(data.status == "200") {
							layer.msg(data.msg, {icon: 1});
							setTimeout(function() {
								location.reload();
							},1000);
						} else{
							layer.msg(data.msg);
						}
					})
				}, function(){
						//layer.msg('已取消');
				});
			})

			//- 查看评论
			$(".allLists").on("click","a.lookPj",function(){
				$(this).closest(".lookComment").show();
			})
			//- 点击删除
			$(".allLists").on("click",".delete1",function(){
				$(this).closest(".listOne").remove();
			})

			//- 点击进入订单详情
			$(".allLists").on("click",".orderLinkDatail",function(){

				if($(this).closest(".listOne").attr("type") == 0) {
					window.location.href = "../shopping/orderDetails_d.html?order_id=" + $(this).closest(".listOne").attr("orderid");
				}else if($(this).closest(".listOne").attr("type") == 1) {
					if($(this).closest(".listOne").attr("skuid") == "") {
						window.location.href = "../shopping/neworderDetails.html?order_id=" + $(this).closest(".listOne").attr("orderid");
					}else{
						window.location.href = "../shopping/orderDetails.html?order_id=" + $(this).closest(".listOne").attr("orderid");
					}
				}else if($(this).closest(".listOne").attr("type") == 2) {
					window.location.href = "../shopping/designorderDetails.html?order_id=" + $(this).closest(".listOne").attr("orderid");
				}else if($(this).closest(".listOne").attr("type") == 3) {
					window.location.href = "../shopping/installorderDetails.html?order_id=" + $(this).closest(".listOne").attr("orderid");
				}else if($(this).closest(".listOne").attr("type") == 4) {
					window.location.href = "../shopping/carorderDetails.html?order_id=" + $(this).closest(".listOne").attr("orderid");
				}else if($(this).closest(".listOne").attr("type") == 5){
					window.location.href = "../shopping/equiorderDetails.html?order_id=" + $(this).closest(".listOne").attr("orderid");
				}	

			})
			//- 点击确认接单
			$(".allLists").on("click",".sureSh",function() {
				$.get(shopIp+"/OrderSeller/grab?userToken="+token+"&order_id="+$(this).closest(".listOne").attr("orderid"),function(data) {
					if(data.data.status == "200") {
						layer.msg(data.msg);
						setTimeout(function() {
							location.reload();
						},1000)
					}else{
						layer.msg(data.msg);
					}
				})
			})
			//- 点击待发货
			$(".allLists").on("click",".delivery",function() {
				$.post(shopIp+"/OrderSeller/deliverGoods",{
					userToken:token,
					order_id:$(this).closest(".listOne").attr("orderid")
				},function(data) {
					if(data.data.status == "200") {
						layer.msg(data.msg);
						setTimeout(function() {
							location.reload();
						},1000)
					}else{
						layer.msg(data.msg);
					}
				})
			})
			//- 点击退货退款
			$(".allLists").on("click",".refundHM",function() {
				var bStatus = $(this).next(".retire").val();
				if($(this).closest(".listOne").attr("type") == "1") {
					if(bStatus == "60") {
						window.location = "wxrefund.html?order_id="+$(this).closest(".listOne").attr("orderid");
					}
				} else{
					if(bStatus == "60"){
						window.location = "refund.html?order_id="+$(this).closest(".listOne").attr("orderid");
					}
				}
				if(bStatus == "84") {
					window.location.href = "moneyDone.html?order_id="+$(this).closest(".listOne").attr("orderid");
				}else if(bStatus == "80" || bStatus == "81" || bStatus == "82" || bStatus == "83") {
					window.location.href = "supplierProcess.html?order_id="+$(this).closest(".listOne").attr("orderid");
				}else if(bStatus == "90" || bStatus == "91") {
					window.location.href = "systemProcess.html?order_id="+$(this).closest(".listOne").attr("orderid");
				}
			})
			//- 点击拒绝
			$(".allLists").on("click",".refused",function() {
				var $this = $(this);
				$(".refuseMask").show();
				//- 点击确认拒单
				$(".refuseBox .btnSure").click(function() {
					if($(".day").val() == "") {
						layer.msg("请填写报价");
					} else if($(".date").val() == "") {
						layer.msg("请填写工期");
					}else if($(".reason").val() == "") {
						layer.msg("请填写拒绝原因");
					}else{
						$.post(shopIp+"/OrderSeller/ungrab",{
							userToken:token,
							order_id:$this.closest(".listOne").attr("orderid"),
							reason:$(".reason").val(),
							offer_price:$(".day").val(),
							project_time:$(".date").val(),
						},function(data) {
							if(data.data.status == "200") {
								$(".refuseMask").hide();
								layer.msg(data.msg);
								setTimeout(function() {
									location.reload();
								},1000)
							}else{
								layer.msg(data.msg);
							}
						})
					}
				})
			})
			//- 点击取消
			$(".btnCancle").click(function() {
				$(".refuseMask").hide();
			})

			//- 点击同意售后
			$(".allLists").on("click",".agreeSh",function() {
				$.post(shopIp+"/OrderSeller/customerService",{
					userToken:token,
					order_id:$(this).closest(".listOne").attr("orderid"),
					refund_state:"1"
				},function(data) {
					layer.msg(data.msg);
					//- setTimeout(function() {
					//- 	location.reload();
					//- },1000)
				})
			})
			//- 点击拒绝售后
			$(".allLists").on("click",".agreeSh",function() {
				$.post(shopIp+"/OrderSeller/customerService",{
					userToken:token,
					order_id:$(this).closest(".listOne").attr("orderid"),
					refund_state:"2"
				},function(data) {
					layer.msg(data.msg);
					//- setTimeout(function() {
					//- 	location.reload();
					//- },1000)
				})
			})

			//- 点击头像进个人资料
			$(".headPortBox  img").click(function() {
				window.location.href = "personData.html";
			})
		})


